package com.qiwei.puding.app;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.callback.AbsCallback;

import java.lang.reflect.ParameterizedType;

import okhttp3.Response;

/**
 * Created by huzongyao on 2018/10/7.
 */

public abstract class JsonCallback<T> extends AbsCallback<T> {

    @Override
    public T convertResponse(Response response) throws Throwable {
        Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
                .getActualTypeArguments()[0];
        return JSON.parseObject(response.body().string(), clazz);
    }
}
